<%-- 
    Document   : agregar_carrito
    Created on : 24/05/2011, 09:19:17 AM
    Author     : Robert
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="Libros.PMF" %>
<%@ page import="Libros.Libro" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Vector" %>
<%@ page session="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<%    
     HttpSession sesionOk = request.getSession();
     sesionOk.setAttribute("compra","true");
     String xcompra = (String)sesionOk.getAttribute("compra");
     String id=request.getParameter("id");
     String ti=request.getParameter("ti");
     String pr=request.getParameter("pr");
     try{
     if(xcompra!=null && xcompra.equals("true") && id!=null && ti!=null && pr!=null){
        Libro lib = new Libro();
        
        lib.setCodigo(id);
        lib.setTitulo(ti);
        lib.setPrecio(Double.parseDouble(pr));
        Vector<Libro> v = (Vector<Libro>)sesionOk.getAttribute("carrito");
        v.add(lib);        
        sesionOk.setAttribute("carrito",v);           
     }
     response.sendRedirect("portal.jsp");
     }catch(Exception e)
                 {
                      response.sendRedirect("error404.jsp");
                 }
%>